package com.weiyi.portal.controller;


import com.weiyi.common.common.api.CommonResult;

import com.weiyi.portal.modules.ums.model.UmsMember;

import com.weiyi.portal.modules.ums.model.UmsNews;
import com.weiyi.portal.modules.ums.service.UmsMemberService;
import com.weiyi.portal.modules.ums.service.UmsNewsService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 用户主页信息
 */
@RestController
@Api(tags = "用户主页信息表")
@RequestMapping(value = "/userHome")
public class UserHomeController {
    @Autowired
    UmsNewsService umsNewsService;

    @Autowired
    UmsMemberService umsMemberService;

    /**
     * 获取用户的动态数
     * @param id
     * @return
     */
    @RequestMapping("/getNewsNum")
    public CommonResult getNewsNum(@RequestBody Integer id){
        Integer newsNum = umsNewsService.getNewsNum(id);
        return CommonResult.success(newsNum);
    }

    @RequestMapping("/getFollowNum")
    public CommonResult getFollowNum(@RequestBody Integer id){
        UmsMember member = umsMemberService.getById(id);
        if(member==null)return CommonResult.failed();
        return CommonResult.success(member.getFollowNum());
    }

    @RequestMapping("/getFansNum")
    public CommonResult getFansNum(@RequestBody Integer id){
        UmsMember member = umsMemberService.getById(id);
        if(member==null)return CommonResult.failed();
        return CommonResult.success(member.getFansNum());
    }

    @RequestMapping("/getNewsDetail")
    public CommonResult getNewsDetail(@RequestBody Integer id){
        List<UmsNews> news = umsNewsService.getNewsById(id);
        return CommonResult.success(news);
    }

    @RequestMapping("/getFollowDetail")
    public CommonResult getFollowDetail(@RequestBody Integer id){
        List<UmsMember> follow = umsMemberService.getFollowById(id);
        return CommonResult.success(follow);
    }

    @RequestMapping("/getFansDetail")
    public CommonResult getFansDetail(@RequestBody Integer id){
        List<UmsMember> fansById = umsMemberService.getFansById(id);
        return CommonResult.success(fansById);
    }


}
